package com.example.lua_redis_demo;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class TestController {

    @Autowired
    private LuaService luaService;
    @Autowired
    private RedisIdService redisIdService;

    /**
     * 测试id生成
     * @return
     */
    @GetMapping("/id")
    public String getId(){
        return luaService.genId();
    }

    /**
     * 测试限流
     * @return
     */
    @GetMapping("/testRateLimit")
    public Long testRateLimit(){
        return luaService.rateLimit();
    }

    /**
     * 测试lua取对象
     */
    @GetMapping("/test/object")
    public DemoDto testObject(){
        return luaService.getTestObject();
    }

    /**
     * 存对象
     * @return
     */
    @GetMapping("/put")
    public String putTestObejct(){
        return luaService.putTestObejct();
    }

    @GetMapping("/lock/{name}")
    public Boolean lock(@PathVariable String name){
        return luaService.lock("testReleaseLock",name);
    }

    @GetMapping("/release/{name}")
    public Boolean releaseLock(@PathVariable String name){
        return luaService.releaseLock("testReleaseLock",name);
    }

    @GetMapping("/mget/{name1}/{name2}/{name3}")
    public List<Object> mget(@PathVariable String name1,
                             @PathVariable String name2,
                             @PathVariable String name3){
        return luaService.mget(name1,name2,name3);
    }

    @GetMapping("/testId")
    public Integer genId(){
        return redisIdService.genId(99,9);
    }




}
